package com.example.yiwei.crm.json;

import com.example.yiwei.crm.entity.BZFLEntity;
import com.example.yiwei.crm.entity.HospitalEntity;
import com.example.yiwei.crm.entity.KSEntity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by DHN on 2017/5/2.
 */

public class YYSpinnerJson {
    public static List<HospitalEntity> getHospital(String result){
        List<HospitalEntity> list ;
       HospitalEntity hospitalEntity;
        try {
            JSONObject object = new JSONObject(result);
            JSONArray array=object.getJSONArray("list");
            list = new ArrayList<>();
            for (int i=0;i<array.length();i++){
                hospitalEntity = new HospitalEntity();
                JSONObject json=array.getJSONObject(i);
                if (json.has("UAA03")){
                    hospitalEntity.setName(json.getString("UAA03"));
                }
                if (json.has("UAA02")){
                    hospitalEntity.setBianma(json.getString("UAA02"));
                }
                if (json.has("UAA01")){
                    hospitalEntity.setId(json.getInt("UAA01"));
                }

                list.add(hospitalEntity);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;

    }
    public static List<KSEntity> getKS(String result){
        List<KSEntity> list ;
        KSEntity hospitalEntity;
        try {
            JSONObject object = new JSONObject(result);
            JSONArray array=object.getJSONArray("list");
            list = new ArrayList<>();
            for (int i=0;i<array.length();i++){
                hospitalEntity = new KSEntity();
                JSONObject json=array.getJSONObject(i);
                if (json.has("ADD03")){
                    hospitalEntity.setName(json.getString("ADD03"));
                }
                if (json.has("ADD02")){
                    hospitalEntity.setBianma(json.getString("ADD02"));
                }

                list.add(hospitalEntity);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;

    }
    public static List<BZFLEntity> getBZFL(String result){
        List<BZFLEntity> list ;
        BZFLEntity hospitalEntity;
        try {
            JSONObject object = new JSONObject(result);
            JSONArray array=object.getJSONArray("list");
            list = new ArrayList<>();
            for (int i=0;i<array.length();i++){
                hospitalEntity = new BZFLEntity();
                JSONObject json=array.getJSONObject(i);
                if (json.has("AKB03")){
                    hospitalEntity.setName(json.getString("AKB03"));
                }
                if (json.has("AKB01")){
                    hospitalEntity.setId(json.getInt("AKB01"));
                }

                list.add(hospitalEntity);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;

    }
    public static List<BZFLEntity> getQDFL(String result){
        List<BZFLEntity> list ;
        BZFLEntity hospitalEntity;
        try {
            JSONObject object = new JSONObject(result);
            JSONArray array=object.getJSONArray("list");
            list = new ArrayList<>();
            for (int i=0;i<array.length();i++){
                hospitalEntity = new BZFLEntity();
                JSONObject json=array.getJSONObject(i);
                if (json.has("AKC03")){
                    hospitalEntity.setName(json.getString("AKC03"));
                }
                if (json.has("AKC01")){
                    hospitalEntity.setId(json.getInt("AKC01"));
                }

                list.add(hospitalEntity);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;

    }
    public static List<BZFLEntity> getQDLY(String result){
        List<BZFLEntity> list ;
        BZFLEntity hospitalEntity;
        try {
            JSONObject object = new JSONObject(result);
            JSONArray array=object.getJSONArray("list");
            list = new ArrayList<>();
            for (int i=0;i<array.length();i++){
                hospitalEntity = new BZFLEntity();
                JSONObject json=array.getJSONObject(i);
                if (json.has("AKD03")){
                    hospitalEntity.setName(json.getString("AKD03"));
                }
                if (json.has("AKD01")){
                    hospitalEntity.setId(json.getInt("AKD01"));
                }

                list.add(hospitalEntity);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;

    }
    public static List<BZFLEntity> getBZ(String result){
        List<BZFLEntity> list ;
        BZFLEntity hospitalEntity;
        try {
            JSONObject object = new JSONObject(result);
            JSONArray array=object.getJSONArray("list");
            list = new ArrayList<>();
            for (int i=0;i<array.length();i++){
                hospitalEntity = new BZFLEntity();
                JSONObject json=array.getJSONObject(i);
                if (json.has("AKM03")){
                    hospitalEntity.setName(json.getString("AKM03"));
                }
                if (json.has("AKM01")){
                    hospitalEntity.setId(json.getInt("AKM01"));
                }

                list.add(hospitalEntity);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;

    }
    public static List<BZFLEntity> getYLLB(String result){
        List<BZFLEntity> list ;
        BZFLEntity hospitalEntity;
        try {
            JSONObject object = new JSONObject(result);
            JSONArray array=object.getJSONArray("list");
            list = new ArrayList<>();
            for (int i=0;i<array.length();i++){
                hospitalEntity = new BZFLEntity();
                JSONObject json=array.getJSONObject(i);
                if (json.has("AKE03")){
                    hospitalEntity.setName(json.getString("AKE03"));
                }
                if (json.has("AKE01")){
                    hospitalEntity.setId(json.getInt("AKE01"));
                }

                list.add(hospitalEntity);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;

    }
}
